package com.xiaotu.emailspringboot.job;

import com.xiaotu.emailspringboot.service.SendmailService;
import jdk.nashorn.internal.runtime.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;
import sun.rmi.runtime.Log;

import java.sql.Date;
import java.sql.SQLOutput;
import java.sql.Time;

/**
 * @Author xiaotu
 * @Description //TODO
 * @Date 2022/3/21 11:40
 * @ClassName SendEmailJob
 * @Version 1.0
 **/
@Component
@Logger
public class SendEmailJob {
    private String to = "1151172450@qq.com";
    private String subject = "2019-3-22~2022-3-22";
    private String filePath = "C:\\Users\\74666\\Desktop\\小土送给小娜娜.zip";
    @Autowired
    private SendmailService sendmailService;
    @Autowired
    private TemplateEngine templateEngine;
   // @Scheduled(cron = "0/5 * * * * *")
    public void sendOnTime(){
        String rscId = "img01";
        StringBuilder text = new StringBuilder();
        text.append("<html><head></head>");
        text.append("<body><h1>关于我们在一起三年了这件事</h1>");
        text.append("<div><span>&nbsp;我们的爱情始于春天，我们在这四季中不断地见证对方的成长，短暂三载生活依旧，爱你依旧</span></div>");
        text.append("<div><span>&nbsp;我们的爱情始于昨天，我们在今天光景不停地牵挂对方的一切，烂漫明天生活依旧，爱你依旧</span></div>");
        text.append("<div><span>&nbsp;我们的爱情始于微小，我们尝酸甜苦辣坚强地陪在对方的左右，修成正果生活依旧，爱你依旧</span></div>");
        text.append("<div><span>&nbsp;我们的爱情始于微小，我们尝酸甜苦辣坚强地陪在对方的左右，修成正果生活依旧，爱你依旧</span></div>");
        //text.append("<div><span><img src = 'https://xiaotu-file.oss-cn-huhehaote.aliyuncs.com/tupian/2021/10/21/74668347.jpg' width=\"50%\" height=\"50%\"></span></div>");
        text.append("<div><span><img src = 'cid:"+rscId+"' width=\"50%\" height=\"50%\"></span></div>");
        text.append("<div><span>&nbsp;                        一起努力共同进步吧                           </span></div>");
        text.append("</html>");
        String rscPath = "C:\\Users\\74666\\Desktop\\bagua\\74668347.jpg";
        System.out.println("============>"+to);
        System.out.println("============>"+text);
        System.out.println("============>"+subject);
        System.out.println(new Date(System.currentTimeMillis()).getTime());
        String s = sendmailService.sendEmailMethod(to,subject,text.toString(),filePath,rscPath,rscId);
        System.out.println(s);
    }
    @Scheduled(cron = "0 0 0 22 3 *")//
    public void sendMailMethod02(){
        Context context = new Context();
        String flower = templateEngine.process("flower", context);
        String send = sendmailService.sendEmailTemplate(to, subject, filePath, flower);
        System.out.println("模板邮件"+send);
    }


}
